package com.tj.collection.enums;

import com.google.common.collect.Lists;

import java.util.ArrayList;
import java.util.List;

/**
 * Author: pavan
 * Date: 2020/10/27 下午4:02
 */
public enum ChannelMappingEnum {

    //用户&订单 复制来的
    CashMama_To_Cashzone("CashMama_To_Cashzone", Lists.newArrayList("in.cashmama.app", "_copyTo_")),

    //openapi
    FortuneBag_CashZone("FortuneBag_CashZone", Lists.newArrayList("open_api_r360_CashZone_FortuneBag")),
    CashMap_MeraLoan("CashMap_MeraLoan", Lists.newArrayList("open_api_epoch_MeraLoan_CashMap")),

    //app
    LoanZone("LoanZone", Lists.newArrayList("com.vayloan.app")),
    CashZone("CashZone", Lists.newArrayList("in.cashzone.app")),
    MERALOAN("MeraLoan", Lists.newArrayList("in.meraloan.app")),
    CashMama("CashMama", Lists.newArrayList("in.cashmama.app")),
    DhanaDhan("DhanaDhan", Lists.newArrayList("in.dhanadhan.loan")),

    //openapi 兜底
    FortuneBag("FortuneBag", Lists.newArrayList("open_api", "FortuneBag")),
    CashMap("CashMap", Lists.newArrayList("open_api", "CashMap")),
    ;

    private String orderSource;

    private List<String> keywords;

    ChannelMappingEnum(String orderSource, List<String> keywords) {
        this.orderSource = orderSource;
        this.keywords = keywords;
    }

    public String getOrderSource() {
        return orderSource;
    }

    public ChannelMappingEnum setOrderSource(String orderSource) {
        this.orderSource = orderSource;
        return this;
    }

    public List<String> getKeywords() {
        return keywords;
    }

    public ChannelMappingEnum setKeywords(List<String> keywords) {
        this.keywords = keywords;
        return this;
    }

    public static String getSourceByChannel(String channel) {
        if (channel == null) {
            return "";
        }
        for (ChannelMappingEnum mappingEnum : ChannelMappingEnum.values()) {
            int count = 0;
            for (String s : mappingEnum.getKeywords()) {
                if (channel.contains(s)) {
                    count++;
                }
            }
            if (count > 0 && count == mappingEnum.getKeywords().size()) {
                return mappingEnum.getOrderSource();
            }
        }
        return "";
    }

    private static List<String> orderFrom = null;

    public static List<String> orderFrom() {
        if (orderFrom != null) {
            return orderFrom;
        }
        List<String> list = new ArrayList<>();
        list.add(LoanZone.getOrderSource());
        list.add(CashZone.getOrderSource());
        list.add(MERALOAN.getOrderSource());
        list.add(FortuneBag.getOrderSource());
        list.add(CashMap.getOrderSource());
        list.add(CashMama.getOrderSource());
        list.add(DhanaDhan.getOrderSource());
        orderFrom = list;
        return list;
    }

    public static void main(String[] args) {
        System.out.println(getSourceByChannel("in.cashmama.app_cashmama_Organic__copyTo_cashZoneAll"));
    }
}
